<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="CentOS启动流程–POST–Bootloader（BIOS，MBR）–kernel – rootfs —switch root–sbin&#x2F;initldd 打印共享依赖库ldd &#x2F;bin&#x2F;ls | grep -o &quot;&#x2F;lib[^[:space:]]*&quot; 内核设计体系：单内核、微内核linux：单内核设计，但充分借鉴了微内核设计体系的设计有点，为内核引入了模块化机制； 内核的组">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux内核模块及功能">
<meta property="og:url" content="http://yoursite.com/2020/06/19/21-Linux%E5%86%85%E6%A0%B8%E6%A8%A1%E5%9D%97%E5%8F%8A%E5%8A%9F%E8%83%BD/index.html">
<meta property="og:site_name" content="Lcxiao&#39;s blog">
<meta property="og:description" content="CentOS启动流程–POST–Bootloader（BIOS，MBR）–kernel – rootfs —switch root–sbin&#x2F;initldd 打印共享依赖库ldd &#x2F;bin&#x2F;ls | grep -o &quot;&#x2F;lib[^[:space:]]*&quot; 内核设计体系：单内核、微内核linux：单内核设计，但充分借鉴了微内核设计体系的设计有点，为内核引入了模块化机制； 内核的组">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-06-19T06:49:19.000Z">
<meta property="article:modified_time" content="2020-06-19T14:49:36.765Z">
<meta property="article:author" content="lcxiao">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yoursite.com/2020/06/19/21-Linux%E5%86%85%E6%A0%B8%E6%A8%A1%E5%9D%97%E5%8F%8A%E5%8A%9F%E8%83%BD/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Linux内核模块及功能 | Lcxiao's blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="Lcxiao's blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Lcxiao's blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-lifestyle">

    <a href="/lifestyle/" rel="section"><i class="fa fa-fw fa-lifestyle"></i>LifeStyle</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/19/21-Linux%E5%86%85%E6%A0%B8%E6%A8%A1%E5%9D%97%E5%8F%8A%E5%8A%9F%E8%83%BD/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Linux内核模块及功能
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-19 14:49:19 / 修改时间：22:49:36" itemprop="dateCreated datePublished" datetime="2020-06-19T14:49:19+08:00">2020-06-19</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="CentOS启动流程–POST–Bootloader（BIOS，MBR）–kernel-–-rootfs-—switch-root–sbin-init"><a href="#CentOS启动流程–POST–Bootloader（BIOS，MBR）–kernel-–-rootfs-—switch-root–sbin-init" class="headerlink" title="CentOS启动流程–POST–Bootloader（BIOS，MBR）–kernel – rootfs —switch root–sbin/init"></a>CentOS启动流程–POST–Bootloader（BIOS，MBR）–kernel – rootfs —switch root–sbin/init</h2><h2 id="ldd-打印共享依赖库"><a href="#ldd-打印共享依赖库" class="headerlink" title="ldd 打印共享依赖库"></a>ldd 打印共享依赖库</h2><p><code>ldd /bin/ls | grep -o &quot;/lib[^[:space:]]*&quot;</code></p>
<p>内核设计体系：<br>单内核、微内核<br>linux：单内核设计，但充分借鉴了微内核设计体系的设计有点，为内核引入了模块化机制；</p>
<h2 id="内核的组成部分："><a href="#内核的组成部分：" class="headerlink" title="内核的组成部分："></a>内核的组成部分：</h2><pre><code>kernel：内核核心，一般为bzimage，通常位于/boot目录、名称为vmlinuz-VERSION-release;
kernel object：内核对象，即内核模块、一般防止与/lib/modules/VERSION-release/
    内核模块与内核核心版本一定要严格匹配；
    [ ]：N
    [M]：Module
    [*]：Y、编译至内核核心
内核模块：动态装载和卸载；</code></pre><p>ramdisk ：辅助性文件，并非必须的，这取决与内核是否能直接驱动rootfs所在的设备；<br>    目标设备驱动，例如SCSI设备的驱动；<br>    逻辑设备驱动，例如LVM设备的驱动<br>    文件系统，例如xfs文件系统；</p>
<pre><code>ramdisk：是一个简装版的根文件系统；（运行与内存的系统）
下一步要做跟切换，持久化</code></pre><h2 id="内核信息获取："><a href="#内核信息获取：" class="headerlink" title="内核信息获取："></a>内核信息获取：</h2><h3 id="uname-：print-system-information"><a href="#uname-：print-system-information" class="headerlink" title="uname ：print system information"></a>uname ：print system information</h3><pre><code>-a ：all
-r ：release号，发行号
-m ：machine 平台架构
-n ：当前主机名</code></pre><p>模块信息获取：</p>
<h3 id="lsmod"><a href="#lsmod" class="headerlink" title="lsmod"></a>lsmod</h3><p>显示当前系统的</p>
<h3 id="modinfo"><a href="#modinfo" class="headerlink" title="modinfo"></a>modinfo</h3><p>显示模块详细信息；<br>-F field    ：仅显示指定字段的信息<br>-n 显示文件路径</p>
<h3 id="modprobe"><a href="#modprobe" class="headerlink" title="modprobe"></a>modprobe</h3><p>实现模块动态装载卸载<br>默认是/etc/modprobe.conf<br>格式:<br><code>modprobe MODULE_NAME</code> 装载模块<br><code>modprobe -r MODULE_NAME</code> ：卸载模块</p>
<p>不要随便卸载模块，除非你知道自己在做什么；</p>
<h3 id="depmod"><a href="#depmod" class="headerlink" title="depmod"></a>depmod</h3><p>生成modules.dep和map文件；<br>内核模块依赖关系生成的工具；</p>
<h3 id="模块的装载和卸载的另一组命令："><a href="#模块的装载和卸载的另一组命令：" class="headerlink" title="模块的装载和卸载的另一组命令："></a>模块的装载和卸载的另一组命令：</h3><p><code>insmode</code><br>    <code>insmode [filename] [module options...]
        filename :模块的文件路径</code>rmmode<code></code>rmmod btrfs`<br>    rmmod [-f] [-s] [-v] [modulename]</p>
<p>ramdisk 文件的管理；</p>
<ol>
<li>mkinitrd<ol>
<li>为使用中的内核重新制作ramfs文件；</li>
<li>–with=<module>：除了默认的模块之外需要装载至initramfs中的模块</li>
<li>–preload=<module>:initramfs所提供的模块需要预先装载的模块；</li>
<li>mkinitrd /boot/initramfs-$(uname -r) $(uname -r)</li>
</ol>
</li>
<li>dracut   较为底层的制作initramfs文件的工具（选项较多，强大）<ol>
<li>dracut [option…] <image> [<kernel version>]<br>例：<code>dracut initramfs-$(uname -r).img $(uname -r)</code></li>
</ol>
</li>
</ol>
<h2 id="操作系统上的两个伪文件系统："><a href="#操作系统上的两个伪文件系统：" class="headerlink" title="操作系统上的两个伪文件系统："></a>操作系统上的两个伪文件系统：</h2><p>/proc<br>    内核状态及统计信息的输出接口；同时，还提供了一个配置接口：/proc/sys<br>    参数：<br>        只读；信息输出/proc/#/*<br>        可写：可接受用户指定的一个“新值“来实现对内核某功能和特性的配置；/proc/sys</p>
<p>/sys    调优就是改这里的参数<br>必须充分理解内核各项参数</p>
<p>不应该使用文本编辑器命令去编辑<br>而是应该使用重定向的方式去覆盖里面的值</p>
<ol>
<li>sysctl ：专用的命令</li>
</ol>
<p><code>sysctl net.ipv4.ip_forward</code><br><code>sysctl -w net.ipv4.ip_forward=1</code></p>
<pre><code>sysctl -a ：显示所有可修改的值；
sysctl variable； 对用/proc/sys目录下有对应关系的文件
修改其值：
    #sysctl -w variable=value   写入
    -p ：从指定文件中加载；默认是/etc/sysctl.conf
    直接sysctl -p 就可以，必要时可以添加文件路径；</code></pre><ol start="2">
<li>文件系统命令<br> 查看：cat /proc/sys/net/ipv4/ip_forward<br> 设定：echo “VALUE” &gt; /proc/sys/net/ipv4/ip_forward</li>
</ol>
<p>注意，这两种方式设定的只是当前有效，重启失效<br>要永久有效必须保存至文件/etc/sysctl.conf 、/etc/sysctl.d/*.conf</p>
<p>内核参数：核心转发/proc/sys/net/ipv4/ip_forward<br>        vm.drop_cache   缓存的内存 （0、1、2）<br>        kernel.hostname 主机名<br>        /proc/sys/net/ipv4/icmp_echo_ignore_all 忽略ping操作</p>
<p>sysfs ：/sys 目录<br>输出内核识别出的各硬件设备的相关属性信息，也有内核对硬件特性的可设置参数，对此些参数的修改，即可定制硬件设备工作特性；</p>
<p>udev：通过读取/sys目录下的硬件设备信息，按需为硬件设备创建设备文件；<br>udev 是用户空间程序；正是/sys的存在才能创建设备</p>
<p>专用工具：<br>devadmin<br>hotplug<br>udev为设备创建设备文件时，会读取事先定义好的规则文件，一般在/etc/udev/rules.d/目录下，以及/usr/lib/udev/rules.d/</p>

    </div>

    
    
    
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/06/15/20-grub%E7%B3%BB%E7%BB%9F%E9%85%8D%E7%BD%AE%E4%B8%8E%E4%BD%BF%E7%94%A8/" rel="prev" title="20.grub系统配置与使用">
      <i class="fa fa-chevron-left"></i> 20.grub系统配置与使用
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/06/22/22-Linux%E5%86%85%E6%A0%B8%E6%A8%A1%E5%9D%97%E5%8A%9F%E8%83%BD%E5%AE%9A%E5%88%B6/" rel="next" title="22.Linux内核模块功能定制">
      22.Linux内核模块功能定制 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#CentOS启动流程–POST–Bootloader（BIOS，MBR）–kernel-–-rootfs-—switch-root–sbin-init"><span class="nav-number">1.</span> <span class="nav-text">CentOS启动流程–POST–Bootloader（BIOS，MBR）–kernel – rootfs —switch root–sbin&#x2F;init</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ldd-打印共享依赖库"><span class="nav-number">2.</span> <span class="nav-text">ldd 打印共享依赖库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#内核的组成部分："><span class="nav-number">3.</span> <span class="nav-text">内核的组成部分：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#内核信息获取："><span class="nav-number">4.</span> <span class="nav-text">内核信息获取：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#uname-：print-system-information"><span class="nav-number">4.1.</span> <span class="nav-text">uname ：print system information</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#lsmod"><span class="nav-number">4.2.</span> <span class="nav-text">lsmod</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#modinfo"><span class="nav-number">4.3.</span> <span class="nav-text">modinfo</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#modprobe"><span class="nav-number">4.4.</span> <span class="nav-text">modprobe</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#depmod"><span class="nav-number">4.5.</span> <span class="nav-text">depmod</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#模块的装载和卸载的另一组命令："><span class="nav-number">4.6.</span> <span class="nav-text">模块的装载和卸载的另一组命令：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#操作系统上的两个伪文件系统："><span class="nav-number">5.</span> <span class="nav-text">操作系统上的两个伪文件系统：</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">lcxiao</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">38</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">分类</span>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://163.com/" title="http:&#x2F;&#x2F;163.com" rel="noopener" target="_blank">163</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://baidu.com/" title="http:&#x2F;&#x2F;baidu.com" rel="noopener" target="_blank">baidu</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="/dalipan.com" title="dalipan.com">dalipan</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://google.com/" title="https:&#x2F;&#x2F;google.com" rel="noopener" target="_blank">Google</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">lcxiao</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
